# -*- coding:utf8 -*-
__author__ = "zhangying"
__date__ = "2019/1/23 10:11"

from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

def get_driver():
    capabilities = {
        "platformName": "Android",
        "deviceName": "127.0.0.1:21503",
        "app": "D:\\PythonAppium\\mukewang.apk",
        "appPackage": "cn.com.open.mooc",
        "appActivity": "cn.com.open.mooc.index.splash.MCSplashActivity",
        "noReset": "true"
    }
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",capabilities)
    return driver


#获取屏幕的宽高
def get_size():
    size = driver.get_window_size()
    width = size['width']
    height = size['height']
    return width,height


#向左边滑动
def swipe_left():
    x1 = get_size()[0]/10*9
    y1 = get_size()[1]/2
    x = get_size()[0]/10
    driver.swipe(x1,y1,x,y1)


#向右边滑动
def swipe_right():
    x1 = get_size()[0]/10
    y1 = get_size()[1]/2
    x = get_size()[0]/10*9
    driver.swipe(x1,y1,x,y1)


#向上边滑动
def swipe_up():
    x1 = get_size()[0]/2
    y1 = get_size()[1]/10*9
    y = get_size()[1]/10
    driver.swipe(x1,y1,x1,y)


#向下边滑动
def swipe_dowm():
    x1 = get_size()[0]/2
    y1 = get_size()[1]/10
    y = get_size()[1]/10*9
    driver.swipe(x1,y1,x1,y)


def swipe_on(direction):
    if direction == 'up':
        swipe_up()
    elif direction == 'down':
        swipe_dowm()
    elif direction == 'left':
        swipe_left()
    else:
        swipe_right()


#点击立即登陆按钮
def go_login():
    driver.find_element_by_id('cn.com.open.mooc:id/tv_go_login').click()


#立即登陆利用id
def login():
    driver.find_element_by_id('cn.com.open.mooc:id/account_edit').clear()
    driver.find_element_by_id('cn.com.open.mooc:id/account_edit').send_keys('13524559846')
    driver.find_element_by_id('cn.com.open.mooc:id/password_edit').send_keys('qiao2012')
    driver.find_element_by_id('cn.com.open.mooc:id/login').click()


#立即登陆利用uiautomator
def login_by_uiautomator():
    driver.find_element_by_android_uiautomator('newUiSelector().text("13524559846")').clear()
    driver.find_element_by_android_uiautomator('new UiSelector().text("手机号/邮箱")').send_keys('qiao2012')
    driver.find_element_by_android_uiautomator('new UiSelector().resourceId("cn.com.open.mooc:id/password_edit")').send_keys('111111')

def get_tost():
    time(2)
    driver.find_element_by_id('cn.com.open.mooc:id/account_edit').send_keys('13524559846')
    tost_elemet = ("xpath","//*[contains(@text,'请输入密码')]")
    print(tost_elemet)
    print(WebDriverWait(driver,10,0.1).until(EC.presence_of_all_elements_located()))


driver = get_driver()


# swipe_on('left')
# swipe_on('left')
# swipe_on('left')
# time.sleep(1)
# swipe_on('up')
time.sleep(5)
# go_login()
# login()






